package com.woniuxy.java106crm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.java106crm.entity.Customer;
import com.woniuxy.java106crm.mapper.CustomerMapper;
import com.woniuxy.java106crm.request.ResPage;
import com.woniuxy.java106crm.service.CustomerService;
import com.woniuxy.java106crm.vo.CustomerVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service
public class CustomerServiceImpl implements CustomerService {
    @Resource
    private CustomerMapper customerMapper;
    @Override
    public ResPage<List<Customer>> findAllCustomers(Integer page, Integer size) {
        PageHelper.startPage(page, size);
        List<Customer> customersList = customerMapper.findAllCustomers();
        PageInfo<Customer> info = new PageInfo<>(customersList);
        ResPage<List<Customer>> resPage = new ResPage<>();
        resPage.setSize(size);
        resPage.setCurPage(page);
        resPage.setTotal(info.getTotal());
        resPage.setData(customersList);
        return resPage;
    }

    @Override
    public boolean updateCustomer(Customer customer) {
        return customerMapper.updateCustomer(customer);
    }

    @Override
    public void updateStatusById(String id) {
        customerMapper.updateStatusById(id);
    }

    @Override
    public boolean addCustomer(CustomerVo customerVo) {
        return customerMapper.addCustomer(customerVo);
    }

    @Override
    public ResPage<List<Customer>> queryCondition(Integer page, Integer size, Customer customer) {
        PageHelper.startPage(page, size);
        List<Customer> customersList = customerMapper.queryCondition(customer);
        PageInfo<Customer> info = new PageInfo<>(customersList);
        ResPage<List<Customer>> resPage = new ResPage<>();
        resPage.setSize(size);
        resPage.setCurPage(page);
        resPage.setTotal(info.getTotal());
        resPage.setData(customersList);
        return resPage;
    }
}
